using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Data.OleDb;

namespace DAOLayer
{
    public class ChiTietHoaDonDao
    {
        public static void Them(ChiTietHoaDonDto cthd)
        {
            // B1 & B2: Tao chuoi ket noi, mo ket noi bang doi tuong ket noi
            OleDbConnection cn = Database.ConnectionData();
            // B3: Tao chuoi strSQL thao tac CSDL
            string strSQL = "Insert into CHITIETHOADON ( MaHoaDon,MaPhieuThue,SoNgayThue,ThanhTien ) values(?,?,?,?)";
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            cmd.Parameters.Add("@MaHoaDon", OleDbType.Integer);
            cmd.Parameters["@MaHoaDon"].Value = cthd.MaHoaDon;
            cmd.Parameters.Add("@MaPhieuThue", OleDbType.Integer);
            cmd.Parameters["@MaPhieuThue"].Value = cthd.MaPhieuThue;
            cmd.Parameters.Add("@SoNgayThue", OleDbType.Integer);
            cmd.Parameters["@SoNgayThue"].Value = cthd.SoNgayThue;
            cmd.Parameters.Add("@ThanhTien", OleDbType.Integer);
            cmd.Parameters["@ThanhTien"].Value = cthd.ThanhTien;
           
            cmd.ExecuteNonQuery();

            strSQL = "Select @@IDENTITY";
            cmd = new OleDbCommand(strSQL, cn);
            cthd.MaChiTietHoaDon = Convert.ToInt32(cmd.ExecuteScalar());
            // B5: Dong ket noi CSDL
            cn.Close();
        }
    }
}
